<?php
namespace App\Models\Msg;

use Illuminate\Database\Eloquent\Model;

/**
 * 添加粉丝信息
 * @author lee
 *
 */
class msgAddFollow extends Model
{
    public static  $STable="lee_msg_befollowed";
    protected  $table="lee_msg_befollowed";
    
    
    /***
     * 添加数据记录 ['userid'=>1,'followedid'=>2]
     * @param array $Item
     */
    static public function addItem(array $Item){
        $inst=new msgAddFollow();
        foreach ($Item as $k=>$v){
            $inst->$k=$v;
        }
        $inst->save();
    }
    
    /**
     * 删除 数据记录 ['userid'=>1,'followedid'=>2]
     * @param array $Item
     */
    static  public function dltItem(array $Item){
        self::where($Item)->delete();
    }
    
  
    /**
     * 获取未读消息
     * @param unknown $userid
     * @param int $lmt
     * @param int $offset 
     */
    static public function getUnreadMsg($userid,$lmt=10,$offset=0){
       return  self::where(['userid'=>$userid,'ispushed'=>false])->select('id','followedid')
            ->offset($offset)->limit($lmt)->get();
    }
    
    /**
     * 返回已读 信息
     * @param unknown $userid
     * @param number $lmt
     * @param number $offset
     */
    static public function getReadMsg($userid,$lmt=10,$offset=0){
        return  self::where(['userid'=>$userid,'ispushed'=>true])->select('id','followedid')
            ->offset($offset)->limit($lmt)->get();
    }
    
    /***
     * 返回  用户的  未推送消息个数
     * @param int $userid
     */
    static public function msgCount($userid){
        return self::where(['userid'=>$userid,'ispushed'=>false])->count();
    }
    
    
    
    /***
     *  标识信息已推送
     * @param  $msgid
     */
    static public function markReaded($msgid){
        self::where('id',$msgid)->update('ispushed',true);
    }
    
}

?>